<div id="maincontent">
	<div id="content">
    
    <h2><?php echo lico_lang('distribution', 'page.title'); ?></h2>
    
    <div class="box1">
      <?php
      if (isset($_GET['a']) && urldecode(trim($_GET['a'])) != "") {
        $distrib = html_entity_decode(str_replace("_S_", "/", urldecode(trim($_GET['a']))));
        include($lico['libs_path']."correct.dist.versions.lib.php");
        echo "<h1>".str_replace("#distribution#", htmlspecialchars($distrib), lico_lang('distribution', 'box1.page.title'))."</h1>\n";
        $sel = "SELECT COUNT(m.f_key) AS num FROM `machines` m LEFT JOIN `users` u ON (u.`f_key`=m.`owner`) WHERE u.`state`=1 AND m.`publish_versions`='YES' AND m.`isactive`='YES' AND m.`distversion`!='' AND LOWER(m.distribution)='".lico_ESC(strtolower($distrib))."'";
        $ret = $db->aselect($sel);
        $gesamt = intval($ret[0]['num']);
        if ($gesamt <= 0) {
          echo "<br/><br/><div style=\"text-align: center; font-weight: bold;\">No machine has this distribution installed!</div>";
        } else {
          ?>
            <div class="infotable-line <?php echo $class; ?>">
              <ul class="infotable-ul">
                <li class="infotable-li col30p"><span><strong>Version</strong></span></li>
                <li class="infotable-li col14p"><span><strong>Machines</strong></span></li>
                <li class="infotable-li col56p"><span><strong>Percent</strong></span></li>
              </ul>
            </div>
          <?php
          $select = "SELECT COUNT(m.f_key) AS num, m.distversion FROM `machines` m LEFT JOIN `users` u ON (u.`f_key`=m.`owner`) WHERE u.`state`=1 AND m.`publish_versions`='YES' AND m.`isactive`='YES' AND m.`distversion`!='' AND LOWER(m.distribution)='".lico_ESC(strtolower($distrib))."' GROUP BY m.distversion ORDER BY num DESC";
  				$retdis = $db->aselect($select);
          for ($a=0; $a<count($retdis); $a++) {
            if ($class == "odd") $class = "even"; else $class = "odd";
            $version = stripslashes(trim($retdis[$a]['distversion']));
            $num = intval($retdis[$a]['num']);
            $percent = round((100/$gesamt) * $num, 2);
            ?>
            <div class="infotable-line <?php echo $class; ?>">
              <ul class="infotable-ul">
                <li class="infotable-li col30p"><span><?php echo $version; ?></span></li>
                <li class="infotable-li col14p"><span><?php echo number_format($num); ?></span></li>
                <li class="infotable-li col56p"><?php echo lico_PercentBar($percent); ?></li>
              </ul>
            </div>
            <?php
          }
        }
        ?>
      </div>
      
      <?php
    }
    ?>
  </div>
</div>
